package com.tianji.remark.task;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

import static com.tianji.remark.constants.RedisConstants.LIKE_BIZ_KEY_PREFIX;

@Slf4j
@Component
@RequiredArgsConstructor
public class CopyToSQL {
    private final StringRedisTemplate redisTemplate;
    private static final String ALL_KEY =LIKE_BIZ_KEY_PREFIX  + "*";

    @Scheduled(fixedRate = 10000*60*60)//每一个小时执行一次
    public void ReadRedisToSQL() {
        ArrayList<String> bizIds = new ArrayList<>();
        try (Cursor<String> cursor = redisTemplate.scan(ScanOptions.scanOptions().match(ALL_KEY).build())) {
            while (cursor.hasNext()) {
                String key = cursor.next();
                // 示例：获取 Set 类型的值（根据实际需求调整）
               bizIds.add(key);
            }
        } catch (Exception e) {
            log.error("从 Redis 读取数据时发生错误", e);
        }
        for (String key : bizIds) {
            String bizId = key.substring(LIKE_BIZ_KEY_PREFIX.length());
        }
    }
    }
